#!/usr/bin/env python
# -*- coding: utf_8 -*-
#joao caixinha





##from SQLloader import Converter
##from htmlGenerator import HTMLGenerator
##from Statistics import Statistics
##import csv
##from Graph import Graphic
##
##c = Converter('reb','reb10')
##
##
##buf = c.getValues()
###h=[]
##stat = Statistics(buf)
##reg = stat.numTeachersEstCatYear()
##                 
##graph = Graphic("Teachers per establishment per year","Establishments","Teachers",reg)        
##graph.drawStatTwoOrTree('Academia Militar')
import sys
sys.setdefaultencoding("utf-8")
sys.path.append('/usr/lib/python2.7') 
sys.path.append('/usr/lib/python2.7/plat-linux2') 
sys.path.append('/usr/lib/python2.7/lib-tk')
sys.path.append('/usr/lib/python2.7/lib-old')
sys.path.append('/usr/lib/python2.7/lib-dynload')
sys.path.append('/usr/local/lib/python2.7/dist-packages')
sys.path.append('/usr/lib/python2.7/dist-packages')
sys.path.append('/usr/lib/python2.7/dist-packages/PIL')
sys.path.append('/usr/lib/pymodules/python2.7/gtk-2.0')
sys.path.append('/usr/lib/python2.7/dist-packages/gst-0.10')
sys.path.append('/usr/lib/python2.7/dist-packages/gtk-2.0')
sys.path.append('/usr/lib/pymodules/python2.7')
sys.path.append('/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode')




# import sys

"""
Change JVM heap size for all application servers in a cell
"""
# New heap size is passed as a parameter to the script
max_heap_size=sys.argv[0]

# Get the string with config ids of all serves
server_confids=AdminConfig.list("Server")
# Iterate over all servers - config ids are separated by \n 
for server_confid in server_confids.split("\n"):
    server_confid=server_confid.strip()
    # obtain the type - types are APPLICATION_SERVER, DEPLOYMENT_MANAGER, NODE_AGENT, WEB_SERVER
    server_type=AdminConfig.showAttribute(server_confid, "serverType")
    # we're changing the heap size for application servers - we want to exclude node agents, etc.
    if server_type == "APPLICATION_SERVER":
        server_name=AdminConfig.showAttribute(server_confid, "name")
        # this is the query to get JavaVirtualMachine configuration object for a particular server
        jvm_path="/Server:%s/JavaProcessDef:/JavaVirtualMachine:/" % server_name
        jvm_confid=AdminConfig.getid(jvm_path)
        # "modify" accepts  a list of lists - each list contains name and value (odd choice I must say, why not use tuples?)
        AdminConfig.modify(jvm_confid, [["maximumHeapSize", max_heap_size]])

# Commit our changes to the repository        
AdminConfig.save()

# sys.path.append('javacsv.jar')
# import sys
# sys.setdefaultencoding("utf-8")
# from au.com.bytecode.opencsv import CSVReader,CSVWriter
# from java.io import FileReader,FileWriter
# from SQLloader import JConverter

# entries = "first,second,third".split(",")
# h = ["Código do Docente","Nome","Último Grau","Curso","Categoria","Regime de Tempo","Ano Lectivo","Tipo de Estabelecimento","Nome do Estabelecimento"]
# h2 = []

# for x in h:
# 	h2.append(x.decode("UTF-8"))
# print entries
# print h
# csvW = CSVWriter(FileWriter("/home/admin1/estiglp-5946-python/estiglp1112-5946-python/rebcsv/teste2.csv"))
# csvW.writeNext(h2)
# csvW.close()
#a = JConverter('teste','tab')
#a.createDB(['nome','idade','morada'])
#a.insertDB(['joao','28','rua da vinha'])
#ls = a.getValues()
#print ls
#a.closeDB()

# from SQLloader import Converter

# b = Converter('teste','tab')
# ls = b.getValues()
# print ls
#from JythonApp import App
#a = App()

#print len(stat.getTeachersEstYearCat())
#
#print len(stat.getTeachersEstYearDegree())

#for row in buf:
#    if(rownum == 0):
#        h = row
#        rownum = 1
#        break;
      

#c = Converter('reb','reb10',h)
#
#c.createDB()
#for row in buf:
#    if(rownum > 0):
#        c.insertDB(row)
#        rownum += 1
#        print rownum
#    if(rownum == 30):
#        break
    
#x = c.getTeachersPerEstablisment()       
#for y in x:   
#    print y 
#    
#print'\n\n\n_____________________________________________________________________________________________________________________\n\n\n'

#x = c.getTeachersPerEstablismentPerCategory()      
#for y in x:   
#    print y 
#    
#print'\n\n\n_____________________________________________________________________________________________________________________\n\n\n'
#
#x = c.getTeachersPerEstablismentPerDegree()    
#for y in x:   
#    print y 

#head = ['nome','curso','escola','turma']
#
#table = [['1','2','3','4'],['5','6','7','8'],['9','10','11','12']]
#handler = HTMLGenerator('teste.html',head,table)



